_Pragma("once");

#include <ctime>
#include "EditablePage.h"
#include "DateTimeUtility.h"
#include "NumberEditor.h"
#include "StringUtility.h"
#include "CommandExecutor.h"
#include "LoopManager.h"

class TimePage : public EditablePage {

public:
    TimePage(const int pageNum) : EditablePage(pageNum), mloopManager(LoopManagerSingleton::instance()) {
    }

    ~TimePage() {
    }
    void paint() override;


    void initEditors() override {
        IntEditor* pEditor = new IntEditor(0, 5, 6, 0, 23, 1);//HOUR
        pEditor->format = "%02d";
        editUnits.push_back(BasicEditorSharedPtr(pEditor));

        pEditor = new IntEditor(0, 8, 9, 0, 59, 1);//MINUTE
        pEditor->format = "%02d";
        editUnits.push_back(BasicEditorSharedPtr(pEditor));

        pEditor = new IntEditor(0, 11, 12, 0, 59, 1);//SECOND
        pEditor->format = "%02d";
        editUnits.push_back(BasicEditorSharedPtr(pEditor));

        pEditor = new IntEditor(2, 5, 8, 1997, 2999, 1);    //YEAR
        //  pEditor->init();
        editUnits.push_back(BasicEditorSharedPtr(pEditor));

        pEditor = new IntEditor(2, 10, 11, 1, 12, 1);    //MONTH
        pEditor->format = "%02d";
        editUnits.push_back(BasicEditorSharedPtr(pEditor));

        pEditor = new IntEditor(2, 13, 14, 1, 31, 1);    //DAY
        pEditor->format = "%02d";
        editUnits.push_back(BasicEditorSharedPtr(pEditor));

        pEditor = new IntEditor(3, 11, 15, 10 * 60, 3 * 60 * 60, 600);    //
        //pEditor->init();
        editUnits.push_back(BasicEditorSharedPtr(pEditor));
    }


    /**
     * 为可编辑单元设置初始值
     * 需要在进入编辑模式 和 初始化的时候调用
     */
    void setValue() override {
        std::tm nowTm = DateTimeUtility::getTime();

        static_cast<IntEditor*> (editUnits[2].get())->setValue(nowTm.tm_sec);
        static_cast<IntEditor*> (editUnits[1].get())->setValue(nowTm.tm_min);
        static_cast<IntEditor*> (editUnits[0].get())->setValue(nowTm.tm_hour);
        static_cast<IntEditor*> (editUnits[3].get())->setValue(nowTm.tm_year + 1900);
        static_cast<IntEditor*> (editUnits[4].get())->setValue(nowTm.tm_mon + 1);
        static_cast<IntEditor*> (editUnits[5].get())->setValue(nowTm.tm_mday);
        static_cast<IntEditor*> (editUnits[6].get())->setValue(mloopManager.mmanualModeKeepTime);
        //     editUnits[6]->setValue((int)LoopManager.getInstance().getManualModalRemainTime());
    }


    /**
     * 设置时间数据
     */
    void saveValue() override;


protected:

    LoopManager& mloopManager;
};
